Paths and Grid Information


In [1]:
h5_path = "/home/einar/Documents/GitHub/PCG/fieldopt_output/adgprs7/5SPOT.SIM.H5"
nx = 60
ny = 60
nz = 1

Read Grid Data From HDF5 File


In [12]:
import h5py
import numpy as np

# Read the HDF5 file
h5_file = h5py.File(h5_path, 'r')

# Get the RESTART and FLOW_TRANSPORT groups from the file
h5_restart_group = h5_file['RESTART']
h5_flow_transport_group = h5_file['FLOW_TRANSPORT']

# Get the GRIDPROPTIME table from the FLOW_TRANSPORT group
# It is a three dimensional table [Block, Prop, Time]
#   For a dead oil run:
#     Rows: Nx * Ny * Nz
#     Columns: 3 (status, pressure, S_w)
#     Layers: 1 pr. time step
# 
#   For a black oil run:
#     Rows: Nx * Ny * Nz
#     Columns: 6 (status, pressure, y_oil, x_oil, S_g, S_o)
#     Layers: 1 pr. time step
h5_gridproptime_table = h5_flow_transport_group['GRIDPROPTIME']

# Get the TIMES table from the RESTART group
h5_times_table = h5_restart_group['TIMES']

# Extract the 1D time step vector from the TIMES table
vec_time_steps = h5_times_table[:]  # 1D vector

# Use the shape of the gridproptime table to determine whether this is a black or dead oil run
if h5_gridproptime_table.shape[1] == 3:
    dead_oil = True
    black_oil = False
else:
    dead_oil = False
    black_oil = True

# Initialize arrays that will hold the block data
pressure = np.zeros([len(vec_time_steps), nx, ny, nz])
sat_oil  = np.zeros([len(vec_time_steps), nx, ny, nz])
sat_wat  = np.zeros([len(vec_time_steps), nx, ny, nz])
sat_gas  = np.zeros([len(vec_time_steps), nx, ny, nz])

for t in range(len(vec_time_steps)):
    row = 0
    for z in range(nz):
        for y in range(ny):
            for x in range(nx):
                pressure[t, x, y, z] = h5_gridproptime_table[row, 1, t]
                sat_wat[t, x, y, z] = h5_gridproptime_table[row, 2, t]
                sat_oil[t, x, y, z] = 1 - sat_wat[t, x, y, z]
                row += 1

Plot Data


In [26]:
from matplotlib import pyplot as plt
x = np.arange(0, nx)
y = np.arange(0, ny)
z = sat_oil[0, :, :, 0]

for t in range(len(vec_time_steps)):
    if t == 0:
        p = plt.imshow(z)
        fig = plt.gcf()
        plt.clim()
        plt.title('Oil saturation')
    else:
        z = sat_oil[t, :, :, 0]
        p.set_data(z)
    plt.pause(1.0)

In [ ]: